/*
 * Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
 * This file is part of SIGAR.
 * 
 * SIGAR is free software; you can redistribute it and/or modify
 * it under the terms version 2 of the GNU General Public License as
 * published by the Free Software Foundation. This program is distributed
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

package physicalmachine;

import org.hyperic.sigar.Mem;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.Swap;
import org.hyperic.sigar.cmd.Shell;
import org.hyperic.sigar.cmd.SigarCommandBase;
import static utils.Constants.*;

/**
 * Responsible for obtaining local RAM Memory information
 */
public class Memory extends SigarCommandBase {
    
    private float rAMMemorySize;
    private float rAMMemoryFree;
    private float rAMMemoryUsed;
    private float swapMemorySize;
    private float swapMemoryFree;
    private float swapMemoryPageIn;
    private float swapMemoryPageOut;
    private float swapMemoryUsed;

    public Memory(Shell shell) {
        super(shell);
    }

    public Memory() {
        super();
    }

    /**
     * Responsible for obtaining and setting the total, free and used RAM memory
     * @param args
     * @throws SigarException
     */
    public void output(String[] args) throws SigarException {
        Mem mem   = this.sigar.getMem();
        Swap swap = this.sigar.getSwap();
        rAMMemorySize= mem.getRam();
        rAMMemoryFree= mem.getFree()/1024/1024;
        rAMMemoryUsed = mem.getUsed()/1024/1024;
        swapMemorySize = swap.getTotal()/1024/1024;
        swapMemoryFree = swap.getFree()/1024/1024;
        swapMemoryPageIn =swap.getPageIn()/1024/1024;
        swapMemoryPageOut = swap.getPageOut()/1024/1024;
        swapMemoryUsed = swap.getUsed()/1024/1024;

    }

    /**
     * Responsible for getting the local RAM memory information
     */
    public void getMemoryInfo()
    {
        try {
            output(new String[0]);
        } catch (SigarException ex) {
            System.err.println(ERROR_MESSAGE+"getting the RAM memory: "+ex.getMessage());
        }
    }

    public static void main(String[] args) throws Exception {
        Memory memory = new Memory ();
        memory.getMemoryInfo();
 
    }

    /**
     * @return the RAMMemorySize
     */
    public float getRAMMemorySize() {
        return rAMMemorySize;
    }

    /**
     * @return the RAMMemoryFree
     */
    public float getRAMMemoryFree() {
        return rAMMemoryFree;
    }

    /**
     * @return the RAMMemoryUsed
     */
    public float getRAMMemoryUsed() {
        return rAMMemoryUsed;
    }

    /**
     * @return the SwapMemorySize
     */
    public float getSwapMemorySize() {
        return swapMemorySize;
    }
    
    public float getSwapMemoryFree() {
        return swapMemoryFree;
    }
    
    public float getSwapMemoryPageIn() {
        return swapMemoryPageIn;
    }
    
    public float getSwapMemoryPageOut() {
        return swapMemoryPageOut;
    }
    
    public float getSwapMemoryUsed() {
        return swapMemoryUsed;
    }

}//end of RAMMemory
